/**
 * 
 * XYVENUE 用户管理
 * @author 湖南行云网络科技有限公司
 * 
 **/

import api from '../../utils/request';
export default {
	namespaced: true,
	state: {
		isLogin: false, // 登录状态
		info: {}, // 用户信息
	},
	mutations: {
		setUserInfo(state, data) {
			state.info = data.userInfo;
			uni.setStorageSync("xyvenue:user", data.userInfo);
		},
	},
	actions: {
		// 登录
		async login({
			state,
			commit
		}, data) {
			state.isLogin = true;
			commit('setUserInfo', data);
		},

		async info({
			commit
		}, data) {
			commit('setUserInfo', data);
		},

		// 退出登录
		async logout({
			state
		}) {
			state.isLogin = false;
			state.info = null;
			uni.removeStorageSync('xyvenue:user');
			uni.clearStorage()
		},

		// 获取用户信息
		async getInfo({
			commit
		}) {
			return new Promise((resolve, reject) => {
				api.post({
					url: '/user/refresh',
					success: res => {
						commit('setUserInfo', res);
						resolve(res)
					},
					fail: res => {
						reject(res)
					},
				});
			})
		},

	}
};